#include <iostream>

using namespace std;
int Study_const_point(int argc, char** argv)
{
    class A
    {
          public:
                 A() { cout << "A::Constructor" << endl; m_a=1; }
                 ~A() { cout << "A::Destorctor" << endl; m_a=0;}
                 
                 void Const_OP() const { cout << m_a << endl; }
                 void NonConst_OP() { m_a = 1; }
                 
          private:
                  int m_a;
    };    
    
    A* p=NULL;        // non const point with full access.
    p = new A();      // It can be initialized after declaration
    p->NonConst_OP(); // ?? can access const function?.
    p->Const_OP();   
    
    // const X* declares a pointer, through which you can not change the object
    // cf X.
    const A* p1;
    p1 = p;           // Valid, initialize it after declaration. 
    p1->Const_OP();   // valid, only const functions of class A can be accessed
                      // by p.
    //p->NonConst_OP();    // Invalid, p can not access non-const functions   
    delete p1;        // allocation/deletion, construction/destroction are not 
                      // affected. Through p, the object can be deleted.
    p1 = NULL;        // Valid, p is not const
    
    p = new A();
    // X* const declares a const point, which can only be initialized when it is
    // declared and point can not be changed.
    A* const p2 = p;  
    p2->Const_OP();
    p2->NonConst_OP(); //p2 is const, but it can fully access object A
    delete p2;             
    //p2 = NULL;      //p2 is const, whose value can not be changed.  
     
    p = new A();
    //combine const pointer and const access
    const A* const p3=p;
    p3->Const_OP();
    //p3->NonConst_OP();    //invalid, because it only has const access.
    delete p3;
    //p3 = NULL;            //invalid, because it is a const pointer.
    
    return 0;
}

int Study_Basic(int argc, char** argv)
{
    int rc=0;
    
    int Study_Reference(int argc, char** argv);
    //rc += Study_Reference(argc, argv);
    
    int Study_Constructor(int argc, char** argv);
    //rc += Study_Constructor(argc, argv);
    
    //rc += Study_const_point(argc, argv);
    
    int Study_Inheritance(int argc, char ** argv);
    rc += Study_Inheritance(argc, argv);
     
    return rc;
}
